<?php 
namespace App\Http\Controllers\TongGaoApi;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Mysql\tonggao\article;
use App\Models\Mysql\tonggao\term;
use App\Models\Mysql\tonggao\term_detail;
use App\Models\Mysql\tonggao\sentence;

use ICanBoogie\Inflector;
use App\libraries\diff\Diff;
class TestController extends Controller
{

	const ROUTE_PREFIX = '/api/*';

	protected $request;

	protected $curTime;

	protected $debug;


	/**
	 * 创建新的`DictController`控制器实例
	 * @param \Illuminate\Http\Request $request
	 */
	public function __construct(Request $request)
	{
		
		$this->request = $request;
		$this->error = [];
		$this->curTime = time();

		if(config('app.debug')) {
			$this->debug = true;
			error_reporting(E_ALL | E_STRICT);
		} else {
			$this->debug = false;
		}
	}
	public function test(){
		$sentence = "The classics talk about howBuddha’s karmic body, speech and intent are used unconditionally with no exception – they naturally do exactly what is needed in order to benefit all sentient beings, to constantly provide deliverance for all.";
		$english_pos = "173,3;177,8;186,6";
		
		$r = english_pos_to_word_pos($english_pos,$sentence);
		var_dump($r);
		$punctures = array(",",".","?","!",":",'"',"'","-",";","[","]");
		$sentence2 = $sentence;
		foreach($punctures as $puncture){
			$sentence2 = str_replace($puncture," ",$sentence2);
		}
		$wordInSentence = explode(" ", $sentence2);	
		echo "{$wordInSentence[$r['first']]}...{$wordInSentence[$r['last']]}</br>";
	
		$sentence = "It is one without any deformation";
		$english_pos = "6,3;10,7;18,3;22,11";
		
		$r = english_pos_to_word_pos($english_pos,$sentence);
		var_dump($r);
		$punctures = array(",",".","?","!",":",'"',"'","-",";","[","]");
		$sentence2 = $sentence;
		foreach($punctures as $puncture){
			$sentence2 = str_replace($puncture," ",$sentence2);
		}
		$wordInSentence = explode(" ", $sentence2);	
		echo "{$wordInSentence[$r['first']]}...{$wordInSentence[$r['last']]}</br>";
		
	}
    public function test_plural()
    {
		$inflector = Inflector::get('en');
		$sql = "select id, chinese_key from term";
		$termList = term::select($sql);
		
		
		$nouns = array('ice','mouse','tooth','cheese','bus','quiz','furniture','lilly');
		$plurals = array();
		
		foreach($nouns as $v){
			$plurals []= array($v=> $inflector->pluralize($v));
		}

		return responseJson('ok', array_merge($termList,$plurals), TRUE);
    }
	public function testdiff()
	{
		$str1="However mean your life is,meet it and live it ;do not shun it and call it hardnames.
		It is not so bad as you suppose.
		It looks poorest when you are richest.
		The fault-finder will find faults in paradise.
		Love your life,poor as it is.
		You may perhaps have some pleasant,thrilling,glorious hourss,even in a poor-house.
		The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode;the snow melts before its door as early in the spring.";
		$str2="Whatever mean your life is,meet it and live it ;do not shun it and call it hardnames.
		It is not so worse as you suppose.
		It looks poorest when you are richest.
		The fault-finder will find faults in paradise.
		Love your life,poor as it is.
		You may perhaps have some pleasant,thrilling,glorious hourss,althor in a poor-house.
		The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode;the snow melts before its door as early in the spring.";
		echo '<style type="text/css">

      .diff td{
        padding:0 0.667em;
        vertical-align:top;
        white-space:pre;
        white-space:pre-wrap;
        font-family:Consolas,\'Courier New\',Courier,monospace;
        font-size:0.75em;
        line-height:1.333;
      }

      .diff span{
        display:block;
        min-height:1.333em;
        margin-top:-1px;
        padding:0 3px;
      }

      * html .diff span{
        height:1.333em;
      }

      .diff span:first-child{
        margin-top:0;
      }

      .diffDeleted span{
        border:1px solid rgb(255,192,192);
        background:rgb(255,224,224);
      }

      .diffInserted span{
        border:1px solid rgb(192,255,192);
        background:rgb(224,255,224);
      }

      #toStringOutput{
        margin:0 2em 2em;
      }

    </style>';
		echo Diff::toTable(Diff::compare($str1, $str2,false));
		
		$str1=str_replace(" ","\r",$str1);
		$str2=str_replace(" ","\r",$str2);
		echo Diff::toTable(Diff::compare($str1, $str2,false));
		
		$str1="我\r们\r曾\r经\r迷\r茫\r过\r";
		$str2="曾\r经\r也\r许\r茫\r然\r过\r";
		var_dump(Diff::compare($str1, $str2,false));
		//echo Diff::toTable(Diff::compare($str1, $str2,false));

	}

    public function testdict()
    {
		//var_dump(getWordVariants('elephant')); //'a','one\'s','cake'
		//exit;
		
		//$term = "take the one's vow"; $sentence = "";pos_in_sentence($term, $sentence);
		//exit;
		
		//$term = "a his take the one's vow their"; $sentence = "";
		//echo "$term </br>";
		//pos_in_sentence($term, $sentence);
		//exit;

		//$term = "take the vow"; $sentence = "take the vow";
		//$term = "take the vow"; $sentence = "take the vow.";
		//$term = "take the vow"; $sentence = "take the vowball."; //false
		//$term = "take the vow"; $sentence = "take the vows"; //now false, need to add variants
		//$term = "take the vow"; $sentence = "Due to many reasons, many people do not know how to resolve our intention. Some people take the vow.";
		//$term = "take the vow"; $sentence = "Due to many reasons, many people do not know how to resolve our intention. Some people take blah bla xxx the yyy zzz vow abcdefg."; //got false, some thing wrong?
		//$term = "take it"; $sentence = "a take b it c"; //correct!
		//$term = "take the vow"; $sentence = "take blah bla xxx the yyy zzz vow abcdefg."; //correct
		//$term = "take the vow"; $sentence = "Some people take blah bla xxx the yyy zzz vow abcdefg."; //correct
		//$term = "take the vow"; $sentence = "many people do not know how to resolve our intention. Some people take blah bla xxx the yyy zzz vow abcdefg."; //correct
		//$term = "take the vow"; $sentence = ", many people do not know how to resolve our intention. Some people took blah bla xxx the yyy zzz vows abcdefg."; //correct， case 1
		//$term = "take the vow"; $sentence = "Due to many reasons to take the vow, many people do not know how to resolve our intention. Some people take blah bla xxx the yyy zzz vow abcdefg."; //correct
		//$term = "take the vow"; $sentence = "Due to taking vow, many people do not know how to resolve our intention. Some people took blah bla xxx the yyy zzz vows abcdefg."; //correct， case 2
		
		//新方法cases
		//$term = "take the vow"; $sentence = "Due to taking vow, many people do not know how to resolve our intention. Some people took blah bla xxx the yyy zzz vows abcdefg."; //correct
		//$term = "take a vow"; $sentence = ", many people do not know how to resolve our intention. Some people took blah bla xxx the yyy zzz vows abcdefg."; //correct
		//echo "term=$term<br>sentence=$sentence<br>";
		//pos_in_sentence($term, $sentence);
		
		//发心failure case
		//$sentence="12. If we wish to form ties with an infinite amount of sentient beings within our endless lives, then – in addition to developing the persistence of our heart’s aim – we should also form ties with our benevolent teacher. We should always strive to deepen our predestined relationship with them. By accomplishing this, we will absorb knowledge from our benevolent teacher with each life, and they will continually stimulate and replenish the aim of our heart.";
		//$sentence="and they will continually stimulate and replenish the aim of our heart."; //ok
		//$term="aim of our heart";$sentence="then – in addition to developing the persistence of our heart’s aim – we should also form ties with our benevolent teacher. We should always strive to deepen our predestined relationship with them. By accomplishing this, we will absorb knowledge from our benevolent teacher with each life, and they will continually stimulate and replenish the aim of our heart.";
		//$term="c b"; $sentence="c 1 2 3 4 5 6 7 c b";
		//echo "term=$term<br>sentence=$sentence<br>";
		//pos_in_sentence($term, $sentence);
		
		/*测试发心
		$terms= array('make the vow', "one's decision", 'take the vow', 'have the resolve', 'resolve', "aim of one's heart",'heart aim'); 
		$sql = "select translation from sentence, term_detail where term_id=1 and sentence.id=term_detail.sentence_id and length(translation)>2";
		$r = sentence::select($sql);
		foreach($r as $v){
			$sentence = $v->translation;
			echo "sentence=$sentence<br>";
			foreach($terms as $term){
				//echo "term=$term<br>";
				pos_in_sentence($term, $sentence);
			}
			echo "--------------------</br>";
		}
		
		*/
		//$term = "make the vow";		$sentence = "Most of those seated here are young students. The various causes and conditions that have led to you making the vow to achieve supreme enlightenment and become monks are not easy to come by.";
		//$term = "make the aspiration";		$sentence = "Most of those seated here are young students. The various causes and conditions that have led to you making the aspiration to achieve supreme enlightenment and become monks are not easy to come by.";
		//$term = "cow"; $sentence="one two cow";
		//$term="aspire"; $sentence="III. Living the Illusory Life with Principles, Aspiring to Do Good Continuously";
		//var_dump(explode(".","a......b"));exit;
		//$term="resolve"; $sentence="While others have been presented to the Monastery by their parents……Irrespective of the causes and conditions the resolve to become a monk is the most fundamental. If the motivation is impure or unclear the moment we encounter negative external conditions we will be diverted by them.";
		//$term="resolve"; $sentence="……of resolve";
		//$term="aim of one's heart";$sentence="12. If we wish to form ties with an infinite amount of sentient beings within our endless lives, then – in addition to developing the persistence of our heart’s aim – we should also form ties with our benevolent teacher. We should always strive to deepen our predestined relationship with them. By accomplishing this, we will absorb knowledge from our benevolent teacher with each life, and they will continually stimulate and replenish the aim of our heart.";
//		$term="Buddhist"; $sentence="For non-Buddhists, they go to see a doctor only when they are physically ill, but do not otherwise think of themselves as having issues. They often think it is normal to lose temper, to curse others, or to act with arrogance because having these afflictions is normal.Often, such is the mindset of non-Buddhists because they incorrectly believe that it is normal to have disturbing emotions.";
//		$term="Buddhist"; $sentence="For non-Buddhists, they go to see a doctor only when they are physically ill, but do not otherwise think of themselves as having issues. They often think it is normal to lose temper, to curse others, or to act with arrogance because having these afflictions is normal.Often, such is the mindset of non-Buddhists because they incorrectly believe that it is normal to have disturbing emotions.";
		$term="karmic cause"; $sentence="sentence is As seen in Buddhist scripture, Buddha was surrounded by disciples, some of whom put forward questions, then Buddha expounded dharma accordingly. Those who requested specific revelations are called “catalysts”. The questions proposed by catalysts are the vital karmic cause for the Buddha to reveal dharma.";
		$r=pos_in_sentence($term, $sentence);
		var_dump($r);
    }
	
} //!- TestController
?>
